//
// Created by 84000 on 2021/5/8.
//

#ifndef BASE_TIMESTAMP_H
#define BASE_TIMESTAMP_H
#include <stdio.h>
#include <stdint.h>
#include <sys/time.h>
#include <string>

//timestamp main code from muduo
class Timestamp {
public:
    Timestamp()
     : microSecondsSinceEpoch_(0)
    { }

    Timestamp(int64_t microSecondsSinceEpoch)
     : microSecondsSinceEpoch_(microSecondsSinceEpoch)
    { }

    std::string toString() const
    {
        char buf[100];
        ::sprintf(buf, "%ld", microSecondsSinceEpoch_);
        return buf;
    }

    static Timestamp now()
    {
        struct timeval tv;
        gettimeofday(&tv, NULL);
        int64_t seconds = tv.tv_sec;
        return Timestamp(seconds * 1000 * 1000 + tv.tv_usec);
    }

private:
    int64_t microSecondsSinceEpoch_;
};


#endif //MARK_SERVER_TIMESTAMP_H
